package com.qzsoft.zhjd.asphalt.modules.asphaltmatch.controller;

import java.util.List;

import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.dto.AsphaltMatchHotForAppDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.entity.AsphaltMatchHotEntity;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchHotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName AsphaltMatchHotController
 * @Description 生产配比热料筛分级配控制器
 * @author linhuawei
 * @since 2021-11-22
 */
@RestController
@RequestMapping("/api/asphaltMatchHot")
public class AsphaltMatchHotController {

    @Autowired
    private AsphaltMatchHotService asphaltMatchHotService;

    /**
     * @Title list
     * @Description 获取指定生产级配热料筛分级配列表
     * @param matchId 生产配比主键
     * @return 生产配比热料筛分级配列表
     */
    @GetMapping("/list/{matchId}")
    public Result<List<AsphaltMatchHotEntity>> list(@PathVariable("matchId") String matchId) {
        List<AsphaltMatchHotEntity> list = asphaltMatchHotService.listByMatchId(matchId);
        return ResultUtils.ok(list);
    }

    /**
     * @Title infoForApp
     * @Description 移动应用获取热料筛分数据
     * @param matchId 配方主键
     * @return 热料筛分数据
     */
    @GetMapping("/infoForApp/{matchId}")
    public Result<AsphaltMatchHotForAppDto> infoForApp(@PathVariable("matchId") String matchId){
        AsphaltMatchHotForAppDto data = asphaltMatchHotService.infoForApp(matchId);
        return ResultUtils.ok(data);
    }

    /**
     * @Title save
     * @Description 添加配比热料筛分级配
     * @param list    要添加的数据
     * @param matchId 配比主键
     * @return 添加结果
     */
    @PostMapping("/save/{matchId}")
    public Result<String> save(@RequestBody List<AsphaltMatchHotEntity> list, @PathVariable("matchId") String matchId) {
        asphaltMatchHotService.save(list, matchId);
        return ResultUtils.ok();
    }

    /**
     * @Title save
     * @Description 添加或修改热料配比
     * @param entity 数据对象
     * @return 添加获取修改热料配比
     */
    @PostMapping("/save")
    public Result<String> save(@RequestBody AsphaltMatchHotEntity entity){
        ValidatorUtils.validateEntity(entity);
        asphaltMatchHotService.save(entity);
        return ResultUtils.ok();
    }

}
